<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = [1, , 3, 4, 5]
    let arr2 = arr.filter(function (item) {
      return item >= 3
    }, [4, 5, 6, 7, 8])
    console.log(arr2);
    // Array.prototype.filter2 = function (callback, thisArg) {
    //   if (this === null) {
    //     throw new TypeError('this is null')
    //   }
    //   if (typeof callback !== 'function') {
    //     throw new TypeError('callback is not a function')
    //   }
    //   let res = []
    //   for (let i = 0; i < this.length; i++) {
    //     if (callback.call(thisArg, this[i], [i], this)) {
    //       res.push(this[i])
    //     }
    //   }
    //   return res
    // }
    Array.prototype.filter2 = function (callback, thisArg) {
      if (this === null) {
        throw new TypeError('this is null')
      }
      if (typeof callback !== 'function') {
        throw new TypeError('callback is not a function')
      }
      let res = []
      for (let i = 0; i < this.length; i++) {
        if (callback.callback(thisArg, this[i], i, this)) {
          res.push(this[i])
        }
      }
      return res
    }
    let arr3 = arr.filter(function (item) {
      return item >= 3
    }, [4, 5, 6, 7, 8])
    console.log(arr3);
  </script>
</body>

</html>